﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Automapping;
using FluentNHibernate.Automapping.Alterations;
using Peak.Core;

namespace Peak.Data.NHibernateMaps
{
  public class UserMap : IAutoMappingOverride<User>
  {
    public void Override(AutoMapping<User> mapping)
    {
      mapping.Id(x => x.Id, "id").UnsavedValue(0).GeneratedBy.Identity();      
      mapping.Map(x => x.UserName).Not.Nullable().Unique();
      mapping.Map(x => x.Password).Not.Nullable();
      mapping.Map(x => x.FirstName);//.Not.Nullable();
      mapping.Map(x => x.LastName);//.Not.Nullable();
      mapping.Map(x => x.Email);//.Not.Nullable();
      mapping.References(x => x.DefaultProject);      
      mapping.HasManyToMany(x => x.Roles);
      mapping.References(x => x.Profile).Cascade.All().Not.Nullable();
    }
  }
}